// Copyright (C) 2007 XtractPro (Data Extraction Magazine)
// http://www.xtractpro.com, support@xtractpro.com
//
// This code is provided AS IS, with NO WARRANTY expressed or implied.
// Any use of this free open source code is at your own risk.
//
// You are hereby granted the right to use it and change it,
// provided that you acknowledge XtractPro somewhere in your
// source files, documentation, web site and application.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;

namespace XtractPro.Multimedia
{
    static class Program
    {
        static int NUM_TEST_IMAGES = 1000;              // number of test images
        static string ROOT = "..\\..\\..\\..\\";        // the path to the root of the project
        static string TRAIN_FOLDER = "trainData\\";       // directory with training data
        static string TEST_FOLDER = "testData\\";         // directory with testing data (used for evaluation)

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
//          Application.Run(new MainForm());

            generateTrainImg();
            generateTestImg();
        }

        static CaptchaImage generator = new CaptchaImage();




        static void generateTrainImg()
        {
            int i;

            // train and test parameters don't have to be the same
            generator.Width = 80;
            generator.Height = 80;
            generator.Unique = false;
            generator.FontSize = 60;
            generator.LinesFactor = 0;
            generator.NoiseFactor = 0;
            generator.WarpFactor = 90;
            generator.Length = 1;           // only one char per image


            // name of the jpg file 
            string imageFileName;
            string path = ROOT + TRAIN_FOLDER;

            // "correct.txt" will contain the association between file names and the actual text
            // it is useful for evaluating the performance of our algorithms
            System.IO.StreamWriter texts = new System.IO.StreamWriter(path + "correct.txt");


            for (i = 0; i < NUM_TEST_IMAGES; i++)
            {
                
                imageFileName = "image" + i + ".jpg";
                generator.Text = "";    // create random text
                generator.Image.Save(path + "images\\" + imageFileName, System.Drawing.Imaging.ImageFormat.Jpeg);

                texts.WriteLine(imageFileName + " " + generator.Text);
            }
            texts.Close();
        }

        static void generateTestImg()
        {
            int i;

            // train and test parameters don't have to be the same
            generator.Width = 250;
            generator.Height = 100;
            generator.Unique = false;
            generator.FontSize = 60;
            generator.LinesFactor = 50;
            generator.NoiseFactor = 50;
            generator.WarpFactor = 90;
            generator.Length = 5;

            
            // name of the jpg file 
            string imageFileName;
            string path = ROOT + TEST_FOLDER;

            // "correct.txt" will contain the association between file names and the actual text
            // it is useful for evaluating the performance of our algorithms
            System.IO.StreamWriter texts = new System.IO.StreamWriter(path+"correct.txt");


            for (i = 0; i < NUM_TEST_IMAGES; i++)
            {
                imageFileName = "image" + i + ".jpg";
                generator.Text = "";    // create random text
                generator.Image.Save(path+"images\\"+imageFileName, System.Drawing.Imaging.ImageFormat.Jpeg);

                texts.WriteLine(imageFileName + " " + generator.Text);
            }
            texts.Close();
        }
    }
}